package cn.youqu.happy.module.youqu.dal.mysql.userTell;

import cn.youqu.happy.framework.common.pojo.PageResult;
import cn.youqu.happy.framework.mybatis.core.mapper.BaseMapperX;
import cn.youqu.happy.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.youqu.happy.module.youqu.controller.admin.userTell.vo.UserTellExportReqVO;
import cn.youqu.happy.module.youqu.controller.admin.userTell.vo.UserTellPageReqVO;
import cn.youqu.happy.module.youqu.dal.dataobject.userTell.UserTellDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * 用户说说 Mapper
 *
 * @author 王其岩 20112001045
 */
@Mapper
public interface UserTellMapper extends BaseMapperX<UserTellDO> {
    UserTellDO findOneByIdAndUid(@Param("id") Integer id, @Param("uid") Long uid);

    List<UserTellDO> findAllByPartnersLike(@Param("likePartners") String likePartners, @Param("startIndex") Integer startIndex, @Param("pageSize") Integer pageSize);

    List<UserTellDO> selectPartnerPage(@Param("pageReqVO") UserTellPageReqVO reqVO, @Param("uid") Long uid, @Param("startIndex") Integer startIndex, @Param("pageSize") Integer pageSize);

    int updateNickNameByUid(@Param("updatedNickName") String updatedNickName, @Param("uid") Long uid);

    int updateAvatarByUid(@Param("updatedAvatar") String updatedAvatar, @Param("uid") Long uid);


    default PageResult<UserTellDO> selectPage(UserTellPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<UserTellDO>()
                .eqIfPresent(UserTellDO::getTellStatus, reqVO.getTellStatus())
                .eqIfPresent(UserTellDO::getUid, reqVO.getUid())
                .likeIfPresent(UserTellDO::getActivityName, reqVO.getActivityName())
                .eqIfPresent(UserTellDO::getActivityId, reqVO.getActivityId())
                .likeIfPresent(UserTellDO::getNickName, reqVO.getNickName())
                .eqIfPresent(UserTellDO::getAvatar, reqVO.getAvatar())
                .eqIfPresent(UserTellDO::getTitle, reqVO.getTitle())
                .eqIfPresent(UserTellDO::getSysActivityId, reqVO.getSysActivityId())
                .betweenIfPresent(UserTellDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
                .eqIfPresent(UserTellDO::getRemark, reqVO.getRemark())
                .orderByDesc(UserTellDO::getId));
    }

    default List<UserTellDO> selectList(UserTellExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<UserTellDO>()
                .eqIfPresent(UserTellDO::getTellStatus, reqVO.getTellStatus())
                .eqIfPresent(UserTellDO::getUid, reqVO.getUid())
                .likeIfPresent(UserTellDO::getActivityName, reqVO.getActivityName())
                .eqIfPresent(UserTellDO::getActivityId, reqVO.getActivityId())
                .likeIfPresent(UserTellDO::getNickName, reqVO.getNickName())
                .eqIfPresent(UserTellDO::getAvatar, reqVO.getAvatar())
                .eqIfPresent(UserTellDO::getTitle, reqVO.getTitle())
                .eqIfPresent(UserTellDO::getSysActivityId, reqVO.getSysActivityId())
                .betweenIfPresent(UserTellDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
                .eqIfPresent(UserTellDO::getRemark, reqVO.getRemark())
                .orderByDesc(UserTellDO::getId));
    }

}
